package org.longs.converter.parser;

import org.longs.bean.PalRGB;

import java.awt.*;

public class RepeatAlphaParser implements Parser {

    private int aByte;

    @Override
    public boolean judge(int aByte) {
        this.aByte = aByte;
        return aByte != 0 && aByte >> 5 == 0;
    }

    @Override
    public void analysis(Recorder recorder, BufferedColorListener result) {
        recorder.setFlag("RepeatAlpha");
        byte[] bytes = recorder.getBytes();
        PalRGB[] palRGBs = recorder.getPalRGBs();
        int alpha = bytes[recorder.getOffsetUp()] * 8 & 0xFF;
        PalRGB color = palRGBs[bytes[recorder.getOffsetUp()] & 0xFF];
        for (int i = 0; i < (this.aByte & 31); i++) {
            result.result(new Color(color.getR(), color.getG(), color.getB(), alpha), recorder);
        }
    }


}
